<%@include file="/WEB-INF/common/taglibs.jsp"%>
<script type="text/javascript" src="${ctx}/resources/js/datatable-query.js"></script>
<style>
.table-notification {
	padding:0px 7px 0px 7px; 
	color:#fff;
	background: #ed7a53;
	border-radius:2px;
	-webkit-border-radius:2px;
	-moz-border-radius:2px;
	font-weight:700;
	font-size:12px;
	font-family: Tahoma;
	position: absolute;
	right:-10px;
	-webkit-box-shadow:  0px 1px 0px 0px rgba(0, 0, 0, 0.2);
	-moz-box-shadow: 0px 1px 0px 0px rgba(0, 0, 0, 0.2);
    box-shadow:  0px 1px 0px 0px rgba(0, 0, 0, 0.2);
    text-shadow:none;
}
</style>
<div class="row-fluid">
<div class="span12">
<div class="box gradient">
<div class="title">
<h4><span>Post</span>



</h4>
<a href="#" class="minimize">Minimize</a></div>
<div class="content scrollable clearfix">
<table class="ajaxTable display table table-bordered">
	<thead>
		<tr>
			<th><a id="select_all"><span class="icomoon-icon-checkmark-2"></span></a></th>
 			<th>Title</th>
 			<th>Auth</th>
			<th>Create Time</th>
			<th>Recommended</th>
			<th>Top</th>
 			<th>Action</th>
		</tr>
	</thead>
</table>
</div>
</div>

</div>
</div>

<script type="text/javascript">
var render = false;

 $(document).ready(function () {
	johnny.oTable = $('.ajaxTable').dataTable({
		"bLengthChange": true,
		"sAjaxSource": '${ctx}/admin/category-post',
		"aoColumnDefs": [
			       		  { 'bSortable': false, 'aTargets': [0,5] }
			       		],
		"fnInitComplete": function (oSettings, json) { }
	});
	var name = $("<input>").attr({
		type: "text",
		field: "title",
		op: "cn",
		placeholder: "Title",
		class: "filterdata"
	});
	johnny.initTableQuery(name);
	var config = {
			id : 'del',
			text  : 'Del',
			domain : "Article",
			operation : "Delete",
			url : "${ctx}/admin/category-post/del/"
	};
	johnny.tableBtn(config);
	
	
	var recommend = {
			id : 'recommend',
			text  : 'Recommend',
			domain : "Recommend",
			operation : "Recommend",
			url : "${ctx}/admin/category-post/recommend/"
	};
	johnny.tableBtn(recommend);
	
	
	var revoke = {
			id : 'revoke',
			text  : 'Revoke',
			domain : "revoke",
			operation : "revoke",
			url : "${ctx}/admin/category-post/revoke/"
	};
	johnny.tableBtn(revoke);
	
	
	var top = {
			id : 'top',
			text  : 'Top',
			domain : "post",
			operation : "top",
			url : "${ctx}/admin/category-post/top-blog/"
	};
	johnny.tableBtn(top);
	
	
	var untop = {
			id : 'untop',
			text  : 'Untop',
			domain : "Post",
			operation : "untop",
			url : "${ctx}/admin/category-post/untop-blog/"
	};
	johnny.tableBtn(untop);
  });
 
var columnHeader = ['','title', 'auth','createDate','recommended','topBlog'];
var QueryData = function (aoData) {
	return johnny.initQueryData(aoData, columnHeader);
}

var DataTableForm = function (json, echo) {
	var dataArray = new Array();
	for (var i = 0; i < json.result.length; i++) {
		var subArray = new Array();
		var value = johnny.getForSelect(json.result[i].id);
 		subArray.push(value);
 		var link = "${ctx}/admin/category-post/"+json.result[i].id+"/edit/";
		var detail = "${ctx}/admin/category-post/"+json.result[i].id+"/detail/";
		var comment = "${ctx}/admin/category-post-comment/"+json.result[i].id+"/list/";
		subArray.push(json.result[i].title);
		subArray.push(json.result[i].auth);
		subArray.push(json.result[i].createDate);
		subArray.push(json.result[i].recommended);
		subArray.push(json.result[i].topBlog);
		
		var number = json.result[i].comments - json.result[i].actives;
		
		
		
		if (number>0){
			var conf = [{
				link : link,
				text : 'edit',
				css   : 'icomoon-icon-pencil'
			},
			{
				link : detail,
				text : 'detail',
				css   : 'icomoon-icon-eyedropper'
				
			},{
				link : comment,
				text : 'comment',
				css   : 'icomoon-icon-copy-2'
				
			}];
			subArray.push(johnny.getGridLink(conf));
			
		}else{
			var conf = [{
				link : link,
				text : 'edit',
				css   : 'icomoon-icon-pencil'
			},
			{
				link : detail,
				text : 'detail',
				css   : 'icomoon-icon-eyedropper'
				
			}];
			subArray.push(johnny.getGridLink(conf));
 		}
 		
// 		subArray.push(actionHtml(json.result[i].id,json.result[i].comments - json.result[i].actives));
 
		dataArray.push(subArray);
	}
	return {
		sEcho: echo,
		iTotalRecords: json.totalCount,
		iTotalDisplayRecords: json.totalCount,
		aaData: dataArray
	};
}

function actionHtml(id,number) {
	var mainSpan = $("<span>");
	var controlDiv = $("<div>").addClass("controls center").appendTo(mainSpan);
	var href = $("<a>").attr({
		href: "${ctx}/admin/category-post/"+id+"/edit/",
		title: "Edit"
	}).addClass("tip").appendTo(controlDiv);
	var span = $("<span>").addClass("icon12 icomoon-icon-pencil").appendTo(href);
	
	
	
	
	if (number>0){
	var comments = $("<a>").attr({
		href: "${ctx}/admin/category-post-comment/"+id+"/list/",
		title: "Approve comments"
	}).addClass("tip").appendTo(controlDiv);
	
	var notification =$("<span>").addClass("table-notification").html(number).appendTo(comments);
	}
 	return mainSpan.html();
}
 
</script>